package com.hspedu.newData.dmsxl.数组;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-20 
 * @Version: 1.0
 */

public class LC3355零数组变换Ⅰ {

    // todo  暴力超时
    public boolean isZeroArray(int[] nums, int[][] queries) {

        int[] deltaArray = new int[nums.length + 1];
        for (int[] query : queries) {
            int left = query[0];
            int right = query[1];
            deltaArray[left] += 1;
            deltaArray[right + 1] -= 1;
        }
        int[] operationCounts = new int[deltaArray.length];
        int currentOperations = 0;
        for (int i = 0; i < deltaArray.length; i++) {
            currentOperations += deltaArray[i];
            operationCounts[i] = currentOperations;
        }
        for (int i = 0; i < nums.length; i++) {
            if (operationCounts[i] < nums[i]) {
                return false;
            }
        }
        return true;
    }

    @Test
    public void test() {
        // 测试代码

        boolean is = isZeroArray(new int[]{8,6},new int[][]{{0,0},{1,1},{0,0},{0,0},{1,1},{0,1},{0,0},{0,0},{1,1},{0,1},{1,1},{0,1},{0,0},{0,0},{0,1}});
        isZeroArray(new int[]{4,3,2,1},new int[][]{{1,3},{0,2}});
    }
}
